﻿using System.Linq;
using xx.yy;
using Tag.Vows.Web;

/// <summary>
///testedit 的摘要说明
/// </summary>
public class testedit : PageBase
{
    public testedit()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    public override CallbackResult DoCallback()
    {
        string action = this.CallValue("action");
        if (action == "edit")
        {
            string id = Request.QueryString["id"];
            int _id = 0;
            if (int.TryParse(id, out _id))
            {
                string title = this.CallValue("title");
                string content = this.CallValue("content");
                var article = __db.Article.FirstOrDefault(x => x.ID == _id);
                if (article != null)
                {
                    article.Title = title;
                    article.Content = content;
                    __db.SaveChanges();

                    return new CallbackResult(new { msg = "修改成功！", article.Title, code = 0 });
                }
                else
                {
                    return new CallbackResult(new { msg = "文章不存在！", code = 1 });
                }
            }
            else
            {
                return new CallbackResult(new { msg = "id有误！", code = 2 });
            }
        }
        return base.DoCallback();
    }
}